using System;
using System.Windows;
using System.Windows.Input;

namespace OrbitOne.CRMLyncInfoDashboard.Setup
{
    public interface IUninstallCommand : ICommand
    {
        void Refresh();
    }

    public class Command
    {
        protected Controller m_controller;
        public Command(Controller controller)
        {
            m_controller = controller;
        }
    }

    public class UninstallCommand : Command, IUninstallCommand
    {
        public UninstallCommand(Controller controller) : base(controller)
        {
        }

        public IInstallCommand InstallCommand { get; set; }

        public void Execute(object parameter)
        {
            var dashboardInstaller = (IDashboardInstaller)parameter;
            if (dashboardInstaller.IsInstalled())
            {
                dashboardInstaller.Uninstall();
            }

            Refresh();
            m_controller.InstallCommand.Refresh();
            MessageBox.Show("Done!");
        }

        public bool CanExecute(object parameter)
        {
            var dashboardInstaller = (IDashboardInstaller)parameter;
            return dashboardInstaller.IsInstalled();
        }

        public void Refresh()
        {
            if (CanExecuteChanged != null)
            {
                CanExecuteChanged(this, EventArgs.Empty);
            }
            m_controller.NotifyPropertyChanged("InstallButtonContent");
        }

        public event EventHandler CanExecuteChanged;
    }
}